<?php
namespace app\hongyanche\controller;
class Upload{
	private function ueditor(){
    	$demand = request()->action();
	    header("Content-Type:text/html;charset=utf-8");
    	$res = model('file')->upload($demand);
		if(!isset($res['state']) || !$res['state']){
			return ['state'=>$res['errormsg']];
		}
		$url = isset($res['data']['url'])?$res['data']['url']:null;
		if($url){
			echo json_encode( ['state'=>'SUCCESS','url'=>$url] );
			die();
		}
			echo json_encode( ['state'=>'url missing'] );
			die();
		return ['state'=>'url missing'];
	}
	private function init(){
		if(input('editorid') == 'myEditor'){
			return json($this->ueditor());
		}
    	$demand = request()->action();
    	$res = model('file')->upload($demand);
		return json($res);
	}
	function mall_article(){
		return $this->init();
	}
	function user(){
		return $this->init();
	}
    //证件照
    public function idPhoto()
    {
        return $this->init();
    }
    //行驶证照片
    public function driving_license()
    {
        return $this->init();
    }
    //广告位
    public function ad()
    {
        return $this->init();
    }

    function forum_article(){
        header("Content-Type:text/html;charset=utf-8");
        $res = model('file')->upload('forum_article');
        if(!isset($res['state']) || !$res['state']){
            return json(['state'=>$res['errormsg']]);
        }
        $url = isset($res['data']['url'])?$res['data']['url']:null;
        if($url){
            echo json_encode( ['errno'=>'0','data'=>[$url]] );
            die();
        }
        echo json_encode( ['errno'=>'1'] );
        die();
        return ['state'=>'url missing'];
    }
    function unit(){
        return $this->init();
    }
    //上传表情
    function expression(){
        return $this->init();
    }
    //手机端上传图片
    public function phoneimg()
    {
        return $this->init();
    }
    function mall(){
        return $this->init();
    }
    function swiper(){
        return $this->init();
    }
    
}